package com.skplanet.rade.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.skplanet.rade.domain.Story;
import com.skplanet.rade.repository.hibernate.HibernateGenericRepository;

@Repository(value="storyDAO")
public class StoryDAO extends HibernateGenericRepository<Story> {
	public StoryDAO(){

	}

	public List<Story> getStoryList(int pg){
		int startIndex = pg * 5 - 5;
		int endIndex = pg * 5;
		
		// where 조건으로 like 검색, 어떤범위에 있는 것을 읽어오고 싶으면
		Criteria criteria = getCriteria();
		criteria.setFirstResult(startIndex);
		criteria.setMaxResults(endIndex);
		criteria.addOrder(Order.desc("regdate"));
		return criteria.list();	
	}
}
